<#import "/spring.ftl" as spring />

<#include "/tags/userNotification.ftl">
<#include "/tags/userCompleteness.ftl">
<#include "/tags/userIntroTag.ftl">
<#include "/tags/friendList.ftl">
<#include "/tags/friendHintTag.ftl">
<#include "/tags/goalCloudTag.ftl">
<#include "/tags/updatedSinceTag.ftl">
<#include "/tags/entryAvatar.ftl">
<#include "/tags/userAvatar.ftl">
<#include "/tags/topGoalsTag.ftl">
<#include "/tags/mustDoGoalWidget.ftl">

<head>	     	
	<link rel="stylesheet" type="text/css" href="${rc.contextPath}/styles/style_dev.css">
	<link rel="stylesheet" type="text/css" href="${rc.contextPath}/styles/jquery.alertbox.css">
	
	<script type="text/javascript" src="${rc.contextPath}/scripts/jquery.nonajax.js"></script>
	<script type="text/javascript" src="${rc.contextPath}/scripts/common.goalUtils.js"></script>	
	<script type="text/javascript" src="${rc.contextPath}/scripts/page.shouldDoGoal.js"></script>
	<script type="text/javascript" src="${rc.contextPath}/scripts/widget.js"></script>
	<script type="text/javascript" src="${rc.contextPath}/dwr/interface/GoalEntryManager.js"></script>
	<script type="text/javascript" src="${rc.contextPath}/scripts/jquery.easing.1.3.js"></script>
	<script type="text/javascript" src="${rc.contextPath}/scripts/jquery.alertbox.js"></script>
	<script type="text/javascript">
		jQuery(document).ready(function(){
			jQuery("input#keyword").keydown(function(e){
				if(e.keycode == 13 || e.which == 13){
					var _keyword = this.value;
					var searchType = ${data.searchType};
					search(_keyword, searchType, 0, null, true);
				}
			});
		});
		
		function search(kw, searchType, _page, nextPageLink, nonajax){
			if(nonajax){
				jQuery.doPost("${rc.contextPath}/search.html",{
								keyword: kw,
								type: searchType,
								page: _page 
							});
			}else{
				jQuery(nextPageLink).fadeOut();
				var _url = "${rc.contextPath}/ajax/secure/search.html";
				jQuery.ajaxSetup({cache:false});
				jQuery.ajax({
					url: _url,
					type: 'POST',
					data: {keyword: kw, type: searchType, page: _page},
					success: function(data){
						if(nextPageLink){
							jQuery(nextPageLink).after(data);
							jQuery(nextPageLink).remove();
						}						
					}
				});
			}			
		}
	</script>
	<title>Kết quả tìm kiếm với từ khóa "${data.keyword}"</title>
</head>

<@userNotification />  
<div class="w3"></div>

<div id="infomation">           
    <!-- user mustDoGoalWidget -->		
    <#if data.mustDoGoal??>
    	<@mustDoGoalWidget data.mustDoGoal.id data.mustDoGoal.title data.mustDoGoal.userCount/>
    </#if>	
	<div id="left">
        <div class="contentHeader">
        	<#assign searchTitle="KẾT QUẢ TÌM KIẾM BẠN BÈ"/>
        	<h1>${searchTitle}</h1> 
            <div class="friendSearchBox">
                <input type="text" name="keyword" id="keyword" value="${data.keyword}"/>
                <input type="hidden" name="searchType" value="${data.searchType}"/>
                <span class="bgPos"></span>
            </div>
         </div> 
         <div class="clearthis"></div>  
        <div class="friendSearchResult">
        	<p class="titleResult">Kết quả tìm kiếm cho từ khóa <b>"${data.keyword}"</b></p>
            
            <div class="clearthis"></div>
            <p class="resultText"><b>${data.countResult}</b> kết quả được tìm thấy</p>
            <#if (data.searchType == 1)>
            <div class="searchResultList">
            	<#if data.resultOfFriendSearch??>
            	<#assign mgR0=""/>
            	<#list data.resultOfFriendSearch as friend>
            	<#if (friend_index % 2 != 0)>
            		<#assign mgR0="mgR0"/>
            	<#else>
            		<#assign mgR0=""/>
            	</#if>
            	<div class="hintFriend ${mgR0}">
                    <div class="avatar"><a href="${rc.contextPath}/${friend.username}">
                    	<@userAvatar username=friend.username avatar=friend.avatar linkClass="" imgWidth="50" imgHeight="50"/>
                    </div>
                    <div class="infofriend">
                        <a href="${rc.contextPath}/${friend.username}" class="friendname">${friend.username}</a>
                        <#if (friend.countMutualFriends > 0)>
                        <div class="text">Có chung ${friend.countMutualFriends} bạn bè</div>
                        <#else>
                        <div class="text">Không có bạn chung</div>
                        </#if>
                        <#if (friend.friend == false)>
                        <a class="followFriend" id="search_friend_result_${friend.id}" href="javascript:followHintFriend(${friend.id},'#search_friend_result_${friend.id}');">KẾT BẠN</a>
                        </#if>
                    </div>
				</div>
            	</#list>
            	<#else>
            		<p></p>
            	</#if>	
        	</div>
        	<#if (data.hasNextPage == true)>
			<div class="wallReadmore" id="next_page">
				<a href="javascript:search('${data.keyword}', ${data.searchType}, ${data.nextPage}, '#next_page');">Hiển thị thêm kết quả</a>
			</div>
			</#if>           
			</#if>
        </div>
    </div>
    
    <div id="right">
		<@userCompleteness />		
		<@topGoals />
		<@userIntro />
        <@friendList username="${data.userInSession}" />
        <@friendHint />
	</div>
</div>
